package com.lyf.controller.user;

import com.lyf.result.Result;
import com.lyf.service.DishService;
import com.lyf.service.SetmealService;
import com.lyf.vo.DishItemVO;
import com.lyf.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@Api(tags = "用户端套餐接口")
@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @Autowired
    private DishService dishService;

    @ApiOperation("根据分类id查询套餐")
    @GetMapping("/list")
    @Cacheable(cacheNames = "setmealCache", key = "#categoryId")
    public Result list(Long categoryId) {
        log.info("根据分类id查询套餐：{}",categoryId);
        List<SetmealVO> list = setmealService.getByCategoryId(categoryId);
        return Result.success(list);
    }

    @ApiOperation("查询套餐中的菜品")
    @GetMapping("dish/{id}")
    public Result dishList(@PathVariable Long id) {
        log.info("根据套餐id查询：{}",id);
        List<DishItemVO> dishes = dishService.getSetmealDIshItemsBySetmealId(id);
        return Result.success(dishes);
    }
}
